package com.org.gameloft.GLIDER.IDE;

import com.org.gameloft.GLIDER.common.GLIDEROptions;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

/**
 * Created by Claudiu-Florin FILIMON
 * Date: Aug 7, 2007
 * Time: 6:46:04 PM
 * Revision: 0
 */
public class GLIDERDialog extends JDialog implements WindowListener
{
    private String propertyName;

    public GLIDERDialog(String name, String title, boolean modal)
    {
        super((Frame) null, title, modal);

        propertyName = name;
        int px = GLIDEROptions.getProperty(name + ".x", 100);
        int py = GLIDEROptions.getProperty(name + ".y", 100);
        int w = GLIDEROptions.getProperty(name + ".width", 600);
        int h = GLIDEROptions.getProperty(name + ".height", 400);

        setBounds(px, py, w, h);

        addWindowListener(this);
    }

    public void windowActivated(WindowEvent e)
    {
    }

    public void windowClosed(WindowEvent e)
    {
    }

    public void windowClosing(WindowEvent e)
    {
        GLIDEROptions.setProperty(propertyName + ".x", getX());
        GLIDEROptions.setProperty(propertyName + ".y", getY());
        GLIDEROptions.setProperty(propertyName + ".width", getWidth());
        GLIDEROptions.setProperty(propertyName + ".height", getHeight());

        GLIDEROptions.save();
    }

    public void windowDeactivated(WindowEvent e)
    {
    }

    public void windowDeiconified(WindowEvent e)
    {
    }

    public void windowIconified(WindowEvent e)
    {
    }

    public void windowOpened(WindowEvent e)
    {
    }
}
